//
//  DiseaseViewController.m
//  KMedicine
//
//  Created by 452608533 on 16/7/7.
//  Copyright © 2016年 caomu. All rights reserved.
//

#import "DiseaseViewController.h"
#import "WJZDYButton.h"
#import "InessTableViewController.h"
#import "ClassificationOfDiseaseController.h"

@interface DiseaseViewController ()

@property(nonatomic,weak)UILabel *userLabel;
@property(nonatomic,weak)UILabel *nameLabel;
@property(nonatomic,weak)UILabel *typeLabel;
@property(nonatomic,weak)UILabel *diseseLabel;
@property(nonatomic,weak)WJZDYButton *selDisButton;
@property(nonatomic,weak)WJZDYButton *moreSelButton;
<<<<<<< HEAD
@property(nonatomic,weak)WJZDYButton *yesNoButton;
@property(nonatomic,weak)WJZDYButton *treatButton;
@property(nonatomic,weak)WJZDYButton *patternButton;
@property(nonatomic,weak)UIImageView *DocImage;
@property(nonatomic,weak)UIButton *applyButton;
@property(nonatomic,weak)UILabel *DocLabel;
=======
//@property(nonatomic,weak)UITextField *tf_separated;
//@property(nonatomic,weak)UIView *lineView;
//@property(nonatomic,weak)UIImageView *imageView;

@property (nonatomic, copy) NSString *name;

>>>>>>> 1353ff4f3605b2daac462be5a3f59f567e1015c6
@end

@implementation DiseaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI {
    
    self.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
    
    //userLabel
    UILabel *userLabel = [[UILabel alloc]init];
    self.userLabel = userLabel;
    userLabel.text = @"用户信息:";
    [userLabel setTextAlignment:NSTextAlignmentCenter];
    NSDictionary *userDict = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:userLabel.text attributes:userDict];
    [userLabel setAttributedText:attr1];
    userLabel.numberOfLines=0;
    [userLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:userLabel];
    
    //nameLabel
    UILabel *nameLabel = [[UILabel alloc]init];
    self.nameLabel = nameLabel;
    nameLabel.text = @"王二狗1000099";
    NSDictionary *nameDict = @{NSAttachmentAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr2 = [[NSAttributedString alloc]initWithString:nameLabel.text attributes:nameDict];
    [nameLabel setAttributedText:attr2];
    nameLabel.numberOfLines=0;
    [nameLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:nameLabel];
    
    //typeLabel
    UILabel *typeLabel = [[UILabel alloc]init];
    self.typeLabel = typeLabel;
    typeLabel.text = @"疾病类型:";
    NSDictionary *typeDict = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr3 = [[NSAttributedString alloc]initWithString:typeLabel.text attributes:typeDict];
    [typeLabel setAttributedText:attr3];
    typeLabel.numberOfLines = 0;
    [nameLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:typeLabel];
    
    //diseseLabel
    UILabel *diseseLabel = [[UILabel alloc]init];
    self.diseseLabel = diseseLabel;
   self.diseseLabel.text = self.title;
    NSDictionary *diseseDict = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:17]};
    NSAttributedString *attr4 = [[NSAttributedString alloc]initWithString:diseseLabel.text attributes:diseseDict];
    [diseseLabel setAttributedText:attr4];
    diseseLabel.numberOfLines = 0;
    [diseseLabel setTextAlignment:NSTextAlignmentLeft];
    [self.view addSubview:diseseLabel];
    
    //疾病细分
    WJZDYButton *selDisButton = [[WJZDYButton alloc]initWithPlaceHolder:@"请选择疾病细分"];
    self.selDisButton = selDisButton;
    [self.view addSubview:selDisButton];
    
    //选择并发症
    WJZDYButton *moreSelButton = [[WJZDYButton alloc]initWithPlaceHolder:@"请选择并发症(可多选)"];
    self.moreSelButton = moreSelButton;
    [self.view addSubview:moreSelButton];
    
     //是否确诊
    WJZDYButton *yesNoButton = [[WJZDYButton alloc]initWithPlaceHolder:@"是否确诊"];
    self.yesNoButton = yesNoButton;
    [self.view addSubview:yesNoButton];
    
    //是否接受治疗
    WJZDYButton *treatButton = [[WJZDYButton alloc]initWithPlaceHolder:@"是否接受治疗"];
    self.treatButton = treatButton;
    [self.view addSubview:treatButton];
    
    
    WJZDYButton *patternButton = [[WJZDYButton alloc]initWithPlaceHolder:@"请选择治疗方式"];
    self.patternButton = patternButton;
    [self.view addSubview:patternButton];
    
    
//    治疗方式
    __weak typeof(self) weakSelf = self;
    
    treatButton.buttonBlock = ^{
        
        [weakSelf setConstraint2];
  
    };
    
    //就医生申请button
    UIButton *applyButton = [[UIButton alloc]init];
    self.applyButton = applyButton;
    [applyButton setBackgroundColor:[UIColor cyanColor]];
    [applyButton setTitle:@"就医生申请" forState:UIControlStateNormal];
    [self.view addSubview:applyButton];
    
    //医生图片image;
    UIImageView *DocImage = [[UIImageView alloc]init];
    self.DocImage = DocImage;
    DocImage.image = [UIImage imageNamed:@"illness_img_person.png"];
    [self.view addSubview:DocImage];
    
    //匹配医生label
    UILabel *DocLabel = [[UILabel alloc]init];
    self.DocLabel = DocLabel;
    DocLabel.text = @"为你匹配到: 42位医生";
    DocLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:DocLabel];
    
    //    添加按钮监听
    //疾病细分监听
    [selDisButton addTarget:self action:@selector(didClikSelButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //选择并发症的监听
    [moreSelButton addTarget:self action:@selector(didClikMoreSelButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //就医生申请的监听
    [applyButton addTarget:self action:@selector(applyButtonDidClik:) forControlEvents:UIControlEventTouchUpInside];
    //为所有控件添加约束
    [self setConstraint1];
    WJLog(@"%@",NSStringFromCGRect(self.DocImage.frame));
}

//就医生申请的监听
- (void)applyButtonDidClik:(UIButton *)sender{
    
    WJLog(@"就医生申请Button");
}

//疾病细分监听
- (void)didClikSelButton:(UIButton *)sender{
    
    ClassificationOfDiseaseController *ClassificationVc = [[ClassificationOfDiseaseController alloc]init];
    ClassificationVc.ClickButtonNumer = self.ClickButtonNumer;
    
    [self.navigationController pushViewController:ClassificationVc animated:YES];
    ClassificationVc.dtoBlock = ^(NSString *name){
        
        self.name = name;
        NSLog(@"self.name = %@",self.name);
    };
    WJLog(@"选择疾病细分");
}

//选择并发症的监听
- (void)didClikMoreSelButton:(UIButton *)sender{
    
    InessTableViewController *inessTableVC = [[InessTableViewController alloc]init];
    
    inessTableVC.cellBlock = ^(NSString *string){
        
        self.moreSelButton.string = string;
    };
    
    [self.navigationController pushViewController:inessTableVC animated:YES];
    
    WJLog(@"选择并发症");
}

#pragma mark -
#pragma mark -为所有控件添加约束
- (void)setConstraint1{
    
    //userLabel
    [self.userLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_topLayoutGuideBottom).offset(20);
        make.leading.equalTo(self.view).offset(10);
        make.height.equalTo(30);
    }];
    
    //nameLabel
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.userLabel.mas_centerY);
        make.leading.mas_equalTo(self.userLabel.mas_trailing).offset(10);
        make.height.equalTo(30);
    }];
    
    //typeLabel
    [self.typeLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.userLabel.mas_bottom).offset(0);
        make.leading.mas_equalTo(self.userLabel.mas_leading).offset(0);
        make.height.equalTo(30);
    }];
    
    //diseseLabel
    [self.diseseLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.typeLabel.mas_centerY);
        make.leading.mas_equalTo(self.typeLabel.mas_trailing).offset(10);
        make.height.equalTo(30);
        
    }];
    
    //疾病细分
    [self.selDisButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.typeLabel.mas_bottom).offset(10);
        make.leading.equalTo(self.view).offset(10);
        make.trailing.equalTo(self.view).offset(-10);
        make.height.equalTo(40);
    }];
    
    //选择并发症
    [self.moreSelButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.selDisButton.mas_bottom).offset(15);
        make.leading.equalTo(self.view).offset(10);
        make.trailing.equalTo(self.view).offset(-10);
        make.height.equalTo(40);
    }];
    
    //是否确诊
    [self.yesNoButton makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.moreSelButton.mas_bottom).offset(15);
        make.leading.equalTo(self.view).offset(10);
        make.trailing.equalTo(self.view).offset(-10);
        make.height.equalTo(40);
        
    }];
    
    //是否接受治疗
    [self.treatButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.yesNoButton.mas_bottom).offset(15);
        make.leading.equalTo(self.view).offset(10);
        make.trailing.equalTo(self.view).offset(-10);
        make.height.equalTo(40);
        
    }];
    
    //就医生申请button
    [self.applyButton makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.mas_equalTo(-20);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.height.equalTo(40);
    }];
    
//    医生图片image
    [self.DocImage makeConstraints:^(MASConstraintMaker *make) {
       
        make.height.equalTo(80);
        make.width.equalTo(80);
        make.centerX.mas_equalTo(self.applyButton.centerX).offset(0);
        make.bottom.mas_equalTo(self.applyButton.mas_top).offset(-20);
    }];
    
    //匹配医生label
    [self.DocLabel makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.mas_equalTo(self.DocImage.mas_top).offset(-20);
        make.leading.equalTo(10);
        make.trailing.equalTo(-10);
        make.height.equalTo(30);
    }];

}

- (void)viewDidLayoutSubviews {
    
    [super viewDidLayoutSubviews];
    WJLog(@"%@",NSStringFromCGRect(self.DocImage.frame));
    self.patternButton.frame = CGRectMake(self.treatButton.frame.origin.x, self.treatButton.frame.origin.y + 20 + self.treatButton.frame.size.height, self.treatButton.frame.size.width, 0);
}

- (void)setConstraint2{
    
    NSLog(@"当前=%lf", self.patternButton.frame.size.height);
    self.patternButton.frame.size.height ? [self ViewNOWithHeight:(0)] : [self ViewNOWithHeight:(40)] ;

}


- (void)ViewNOWithHeight:(int)height {
    
    [UIView animateWithDuration:0.1 animations:^{
        
         self.patternButton.frame = CGRectMake(self.treatButton.frame.origin.x, self.treatButton.frame.origin.y + 20 + self.treatButton.frame.size.height, self.treatButton.frame.size.width, height);
    }];
    
   
    
}

- (void)dealloc {
    
    NSLog(@"控制器挂了");
}


@end














